package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SysIndustry;
import com.ruoyi.system.service.ISysIndustryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCmp;
import com.ruoyi.system.service.ISysCmpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-11-20
 */
@RestController
@RequestMapping("/system/cmp")
public class SysCmpController extends BaseController
{
    @Resource
    private ISysCmpService sysCmpService;

    @Resource
    private ISysIndustryService sysIndustryService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCmp sysCmp)
    {
        startPage();
        List<SysCmp> list = sysCmpService.selectSysCmpList(sysCmp);
//        if (list != null && list.size() > 0) {
//            //加上行业内容
//            for (int i = 0; i < list.size(); i++) {
//                SysIndustry sysIndustry = new SysIndustry();
//                sysIndustry.setIndCode(list.get(i).getIndCode());
//                List<SysIndustry> sysIndustries = sysIndustryService.selectSysIndustryList(sysIndustry);
//                if (sysIndustries != null && sysIndustries.size() > 0) {
//                    list.get(i).setIndustryDetail(sysIndustries.get(0).getEnDetail());
//                }
//            }
//        }
        return getDataTable(list);
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<SysCmp> util = new ExcelUtil<SysCmp>(SysCmp.class);
        List<SysCmp> userList = util.importExcel(file.getInputStream());
        Long opeUserId = getUserId();
        String message = sysCmpService.importCmp(userList, updateSupport, opeUserId);
        return success(message);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCmp sysCmp)
    {
        List<SysCmp> list = sysCmpService.selectSysCmpList(sysCmp);
        ExcelUtil<SysCmp> util = new ExcelUtil<SysCmp>(SysCmp.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysCmpService.selectSysCmpById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCmp sysCmp)
    {
        return toAjax(sysCmpService.insertSysCmp(sysCmp));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCmp sysCmp)
    {
        return toAjax(sysCmpService.updateSysCmp(sysCmp));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:cmp:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysCmpService.deleteSysCmpByIds(ids));
    }
}
